package com.bbs.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bbs.model.Comment;
import com.bbs.server.CommentService;

@Controller
@RequestMapping("/comment")
public class CommentController {

	@Resource
	private CommentService commentService;

	@RequestMapping(value = "/add", method = RequestMethod.GET)
	@ResponseBody
	public String add(Comment comment) {
		commentService.add(comment);
		return "success";
	}

	@RequestMapping(value = "/update", method = RequestMethod.GET)
	@ResponseBody
	public String update(Comment comment) {
		commentService.update(comment);
		return "success";
	}

	@RequestMapping(value = "/delete", method = RequestMethod.GET)
	@ResponseBody
	public String delete(Comment comment) {
		commentService.delete(comment);
		return "success";
	}

	@RequestMapping(value = "/list", method = RequestMethod.GET)
	@ResponseBody
	public List<Comment> getCommentList() {
		List<Comment> users = commentService.getCommentList();
		return users;
	}
	
	@RequestMapping(value="/fenye",method=RequestMethod.GET)
	@ResponseBody
	public List<Comment> fenye(int pageIndex, int pageSize){
		Map<String, Object> data = new HashMap<String, Object>();
		data.put("pageIndex", (pageIndex-1)*pageSize);
        data.put("pageSize", pageSize);
		List<Comment> fenye = commentService.fenye(data);
		return fenye; 
	}
	
	@RequestMapping(value="/chazhao",method=RequestMethod.GET)
	@ResponseBody
	public List<Comment> chazhao(String keyword){
		Map<String, Object> data = new HashMap<String, Object>();
		data.put("pageIndex",keyword);
		List<Comment> fenye = commentService.chazhao(data);
		return fenye; 
	}
}
